/**
 * @ProjectName:Backend
 * @Title: UserMapVo
 * @Package com.phrp.entity.vo
 * @Description: 信息结构体类
 * @author SuShuChao
 * @date 2024/4/4 20:28
 * @version V1.0
 * Copyright (c) 2024, 2034279227@qq.com All Rights Reserved.
 */
package com.phrp.util.returnResult;

import com.phrp.exception.BaseErrorInfoInterface;
import lombok.Data;

/*
    在使用@Data时，会出现其失效的情况（在重新启动并配置这个项目的时候），
        需要先试用clean清除一下，再刷新Maven就可以解决
 */
@Data
public class ResponseResult<T> {

    //给前端传递的信息
    public String msg;

    //传递的状态码
    public String code;

    //传递的数据信息
    public T data;

    public ResponseResult(ReturnInfoEnum returnInfoEnum, T data) {
        this.msg = returnInfoEnum.getResultMsg();
        this.code = returnInfoEnum.getResultCode();
        this.data = data;
    }

    public ResponseResult(ReturnInfoEnum returnInfoEnum) {
        this.msg = returnInfoEnum.getResultMsg();
        this.code = returnInfoEnum.getResultCode();
    }

    public ResponseResult(){}

    /** 失败 **/
    public static ResponseResult error(BaseErrorInfoInterface errorInfo) {
        ResponseResult result = new ResponseResult();
        result.setCode(errorInfo.getResultCode());
        result.setMsg(errorInfo.getResultMsg());
        return result;
    }
    /** 失败 **/
    public static ResponseResult error(String code, String message) {
        ResponseResult result = new ResponseResult();
        result.setCode(code);
        result.setMsg(message);
        return result;
    }
    /** 失败 **/
    public static ResponseResult error(String message) {
        ResponseResult result = new ResponseResult();
        result.setMsg(message);
        return result;
    }


}
